CommonUtils.regNamespace("com.app.index");

com.app.index.invoke = function () {

    // Application Constructor
    function _init() {
        if(isPhone()){
            document.addEventListener('deviceready', onDeviceReady.bind(this), false);
        } else {
            initpage();
        }
    }

    // deviceready Event Handler
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    function onDeviceReady() {
        receivedEvent('deviceready');
    }

    //
    function receivedEvent(id) {
        initpage();
    }

    //是否为手机端
    function isPhone () {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone","iPad"];
        var flag = false;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = true;
                com.app.common.mda.DEVICE_TYPE =  Agents[v];
                break;
            }
        }
        return flag;
    }

    //初始化页面
    function initpage() {
        com.app.common.util.log(`页面开始初始化：` + com.app.common.mda.DEVICE_TYPE);
        $("#gopage2").click(function(){
            window.location.href = "pages/page2.html";
        });
    }

    return {
        init : _init
    }

}();

$(function() {
    com.app.index.invoke.init();
});